﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CsharpHttpHelper;
using CsharpHttpHelper.Enum;
using NPOI.SS.Formula.Functions;

namespace DZDPSpider
{
    public class HttpHelper
    {
        public static string Get(string url)
        {
            CsharpHttpHelper.HttpHelper http = new CsharpHttpHelper.HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = url,//URL     必需项
                Method = "GET",//URL     可选项 默认为Get
                Timeout = 100000,//连接超时时间     可选项默认为100000
                ReadWriteTimeout = 30000,//写入Post数据超时时间     可选项默认为30000
                IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写
                Cookie = "__mta=20697863.1534665009195.1534681353747.1535212015385.22\"; _lxsdk_cuid=1655128a367c8-096e978abc72e5-2711639-144000-1655128a368c8; _lxsdk=1655128a367c8-096e978abc72e5-2711639-144000-1655128a368c8; _hc.v=503fa635-de4b-3f0d-8a71-93aa9517e9e5.1534664943; cityInfo=%7B%22cityId%22%3A99%2C%22cityEnName%22%3A%22taizhou%22%2C%22cityName%22%3A%22%E6%B3%B0%E5%B7%9E%22%7D; cy=99; cye=taizhou; s_ViewType=10; selectLevel=%7B%7D; _lx_utm=utm_source%3DBaidu%26utm_medium%3Dorganic; _lxsdk_s=16571c41d7a-a03-8c9-9b3%7C%7C80",
                UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36",//用户的浏览器类型，版本，操作系统     可选项有默认值
                Accept = "text/html, application/xhtml+xml, */*",//    可选项有默认值
                ContentType = "text/html",//返回类型    可选项有默认值
                Referer = "",//来源URL     可选项
                Allowautoredirect = false,//是否根据３０１跳转     可选项
                AutoRedirectCookie = false,//是否自动处理Cookie     可选项
                                           //CerPath = "d:\123.cer",//证书绝对路径     可选项不需要证书时可以不写这个参数
                                           //Connectionlimit = 1024,//最大连接数     可选项 默认为1024
                Postdata = "",//Post数据     可选项GET时不需要写
                              //ProxyIp = "192.168.1.105：2020",//代理服务器ID     可选项 不需要代理 时可以不设置这三个参数
                              //ProxyPwd = "123456",//代理服务器密码     可选项
                              //ProxyUserName = "administrator",//代理服务器账户名     可选项
                ResultType = ResultType.String,//返回数据类型，是Byte还是String
            };
            HttpResult result = http.GetHtml(item);
            string html = result.Html;
            string cookie = result.Cookie;
            return html;
        }
    }
}
